//
//  MOProductViewController.m
//  FastDoctor
//
//  Created by 冯龙飞 on 16/5/21.
//  Copyright © 2016年 冯龙飞. All rights reserved.
//

#import "MOProductViewController.h"
#import "MOProdectHeadView.h"
#import "MOProdectFootView.h"
#import "MOProductCell.h"
#import <SVProgressHUD/SVProgressHUD.h>

//装箱,使mas_前缀去掉
#define MAS_SHORTHAND

//装箱,去掉mas_eqalTo前缀
#define MAS_SHORTHAND_GLOBALS

@interface MOProductViewController ()

@property(nonatomic, strong) UIView * headView;

@property(nonatomic, strong) UIView * footView;

@end

static NSString *MOProdectHeadViewIdentifier = @"MOProdectHeadViewIdentifier";

static NSString *MOProductCellIdentifier = @"MOProductCellIdentifier";

@implementation MOProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"关于产品";
    
    //重写返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_button_back_01"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    // 添加头部视图
    MOProdectHeadView *head = [[MOProdectHeadView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)];
    
    self.tableView.tableHeaderView = head;
    
    // 添加尾部视图
    MOProdectFootView *foot = [[MOProdectFootView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 386)];
    
    self.tableView.tableFooterView = foot;
    
    [self.tableView registerClass:[MOProductCell class] forCellReuseIdentifier:MOProductCellIdentifier];
    
}

//重写返回按钮,判断是否打开菜单侧滑
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
    [NQNavVc judgeMenuOpen];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MOProductCell *cell = [tableView dequeueReusableCellWithIdentifier:MOProductCellIdentifier forIndexPath:indexPath];
    
    cell.imageView.image = [UIImage imageNamed:@"product_img_icon_xieyi.png"];
    
    cell.textLabel.text = @"关于产品";
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

// 当点击这个cell的时候跳转到一个webview上并加载相应页面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 创建一个控制器
    UIViewController *vc = [[UIViewController alloc]init];
    
    // 创建一个webview并且加到控制器的view上
    UIWebView *webView = [[UIWebView alloc]initWithFrame:vc.view.bounds];
    [vc.view addSubview:webView];
    
    // push到这个控制器上
    [self.navigationController pushViewController:vc animated:YES];
    
    [SVProgressHUD showWithStatus:@"加载中..."];
    
    // 让webview加载网页,这里是随便使用了一个网址
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://passport.baidu.com/protocal.html"]]];
    
    if (!webView.isLoading) {
        [SVProgressHUD dismiss];
    }
    
}


@end
